//
//  FineInfoCell.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/7/12.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import Foundation
class FineInfoCell: UITableViewCell {
    var license_1,license_2,license_3,submitFine:UIButton!
    var haveView,noView,moneyView:UIView!
    var remark:UITextView!
    var samount,price,latePrice:UITextField!//服务费,罚款金额，滞纳金
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCellSelectionStyle.none
        self.layer.borderWidth = 0
        //************************************有单据************************************
        haveView = UIView.init(frame: CGRect(x: 0, y: 0, width: kScreenW, height: cellH + 2*oImgH))
        haveView.isHidden = true
        self.addSubview(haveView)
        let label1 = UILabel.init(frame: CGRect(x: oLabelLeft, y: 0, width: 120, height: cellH))
        label1.font = oFontSize
        label1.text = "罚款单据信息"
        haveView.addSubview(label1)
        
        license_1 = UIButton.init(frame: CGRect(x: oImgLeft, y: oTop + oLabelH, width: oImgW, height: 2*oImgH))
        license_1.setBackgroundImage(UIImage(named:"car_fine"), for: .normal)
        haveView.addSubview(license_1)
        //************************************没有单据************************************
        noView = UIView.init(frame: CGRect(x: 0, y: 0, width: kScreenW, height: cellH + 2*oImgH + oTop))
        noView.isHidden = true
        self.addSubview(noView)
        let label5 = UILabel.init(frame: CGRect(x: oLabelLeft, y: 0, width: oLabelW, height: cellH))
        label5.font = oFontSize
        label5.text = "行驶证信息"
        noView.addSubview(label5)
        
        license_2 = UIButton.init(frame: CGRect(x: oImgLeft, y:oLabelH + oTop, width: oImgW, height: oImgH))
        license_2.setBackgroundImage(UIImage(named:"xingshizheng1"), for: .normal)
        noView.addSubview(license_2)
        
        license_3 = UIButton.init(frame: CGRect(x: oImgLeft, y: oLabelH + 2*oTop + oImgH, width: oImgW, height: oImgH))
        license_3.setBackgroundImage(UIImage(named:"xingshizheng2"), for: .normal)
        noView.addSubview(license_3)
        
        
        moneyView = UIView.init(frame: CGRect(x: 0, y: oTop + cellH + 2*oImgH, width: kScreenW, height: 4*cellH + 6*oTop + remarkH))
        self.addSubview(moneyView)
        
        let label2 = UILabel.init(frame: CGRect(x: oLabelLeft, y: 0, width: 120, height: cellH))
        label2.font = oFontSize
        label2.text = "罚款金额"
        moneyView.addSubview(label2)
        
        price = UITextField.init(frame: CGRect(x: oLabelW, y:0, width: oImgW, height: cellH))
        price.isEnabled = false
        price.backgroundColor = tableBgColor
        price.textColor = fontColor
        price.font = oFontSize
        price.layer.cornerRadius = 5
        moneyView.addSubview(price)
        
        let label3 = UILabel.init(frame: CGRect(x: oLabelLeft, y: oTop + cellH, width: 120, height: cellH))
        label3.font = oFontSize
        label3.text = "滞纳金"
        moneyView.addSubview(label3)
        
        latePrice = UITextField.init(frame: CGRect(x: oLabelW, y:oTop + cellH, width: oImgW, height: cellH))
        latePrice.isEnabled = false
        latePrice.backgroundColor = tableBgColor
        latePrice.textColor = fontColor
        latePrice.font = oFontSize
        latePrice.layer.cornerRadius = 5
        moneyView.addSubview(latePrice)
        
        let label4 = UILabel.init(frame: CGRect(x: oLabelLeft, y: 2*oTop + 2*cellH, width: 120, height: cellH))
        label4.font = oFontSize
        label4.text = "服务费"
        moneyView.addSubview(label4)
        
        samount = UITextField.init(frame: CGRect(x: oLabelW, y:2*oTop + 2*cellH, width: oImgW, height: cellH))
        samount.isEnabled = false
        samount.backgroundColor = tableBgColor
        samount.textColor = fontColor
        samount.font = oFontSize
        samount.layer.cornerRadius = 5
        moneyView.addSubview(samount)
        let remarkLabel = UILabel.init(frame: CGRect(x: oLabelLeft, y: 3*oTop + 3*cellH, width: oLabelW, height: remarkH))
        remarkLabel.font = oFontSize
        remarkLabel.text = "备注信息"
        moneyView.addSubview(remarkLabel)
        
        remark = UITextView(frame:CGRect(x:oLabelW, y:3*oTop + 3*cellH, width:oImgW, height:remarkH))
        remark.layer.cornerRadius = 5
        remark.backgroundColor = tableBgColor
        remark.font = oFontSize
        remark.textColor = fontColor
        remark.isEditable = true
        moneyView.addSubview(remark)
    
        submitFine = UIButton.init(frame:CGRect(x: oLabelLeft, y:5*oTop + 3*cellH + remarkH, width: kScreenW - 2*oLabelLeft, height: cellH))
        submitFine.backgroundColor = appMainColor
        submitFine.showsTouchWhenHighlighted = true
        submitFine.layer.cornerRadius = 10;
        moneyView.addSubview(submitFine)
        
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func configCellDateWithModel(_ model:CarFineModel) {
        let fic = FineInfoController()
        price.text = model.price
        latePrice.text = model.latePrice
        samount.text = model.samount
        remark.text = model.remark
        if "0" ==  model.isDocument{//是否有单据  0:没有，1：有
            noView.isHidden = false
            moneyView.frame.origin.y = 2*oTop + cellH + 2*oImgH
            license_2.sd_setBackgroundImage(with: URL.init(string: "\(projectUrl)/file/download/\(model.driveLicense_2)?tokenID=\(tokenID!)&tokenUserID=\(userID!)"), for: .normal)
            license_3.sd_setBackgroundImage(with: URL.init(string: "\(projectUrl)/file/download/\(model.driveLicense_3)?tokenID=\(tokenID!)&tokenUserID=\(userID!)"), for: .normal)
        }
        if "1" ==  model.isDocument{//是否有单据  0:没有，1：有
            haveView.isHidden = false
            moneyView.frame.origin.y = oTop + cellH + 2*oImgH
            license_1.sd_setBackgroundImage(with: URL.init(string: "\(projectUrl)/file/download/\(model.driveLicense_1)?tokenID=\(tokenID!)&tokenUserID=\(userID!)"), for: .normal)
        }
        if "0" ==  model.ostatus{
            submitFine.setTitle("去支付", for: .normal)
            submitFine.tag = 0
            submitFine.addTarget(fic, action: #selector(fic.operatorFun(sender:)), for: UIControlEvents.touchUpInside)
        }
        if "1" == isEmployee {//普通用户登录
            if "1" == model.ostatus {
                submitFine.setTitle("等待处理", for: .normal)
                submitFine.isEnabled = false
                submitFine.backgroundColor = UIColor.lightGray
            }
            if "2" == model.ostatus {
                submitFine.setTitle("处理中", for: .normal)
                submitFine.backgroundColor = UIColor.lightGray
                submitFine.isEnabled = false
            }
            if "3" == model.ostatus {
                submitFine.setTitle("已处理", for: .normal)
                submitFine.isEnabled = false
                submitFine.backgroundColor = UIColor.lightGray
            }
        }
        if "2" == isEmployee {
            if "1" == model.ostatus {
                submitFine.setTitle("抢单", for: .normal)
                submitFine.tag = 1
                submitFine.addTarget(fic, action: #selector(fic.operatorFun(sender:)), for: UIControlEvents.touchUpInside)
            }
            if "2" == model.ostatus {
                submitFine.setTitle("完成", for: .normal)
                submitFine.tag = 2
                submitFine.addTarget(fic, action: #selector(fic.operatorFun(sender:)), for: UIControlEvents.touchUpInside)
            }
            if "3" == model.ostatus {
                submitFine.setTitle("已完成", for: .normal)
                submitFine.backgroundColor = UIColor.lightGray
                submitFine.isEnabled = false
            }
        }
    }
}
